<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="就业信息名称" prop="rDetailsName" label-width="100px">
        <el-input
          v-model="queryParams.rDetailsName"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位" prop="rDetailsPost">
        <el-input
          v-model="queryParams.rDetailsPost"
          placeholder="请输入岗位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="热招岗位" prop="rDetailsPostHeat">
        <el-input
          v-model="queryParams.rDetailsPostHeat"
          placeholder="请输入热招岗位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['zua:details:add']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['zua:details:edit']"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['zua:details:remove']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['zua:details:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="detailsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="名称" align="center" prop="rDetailsName" show-overflow-tooltip />
      <el-table-column label="简介" align="center" prop="rDetailsRemake" show-overflow-tooltip />
      <el-table-column label="岗位" align="center" prop="rDetailsPost" />
      <el-table-column label="详细热招岗位" align="center" prop="rDetailsPostHeat" />
      <el-table-column label="详细岗位要求" align="center" prop="rDetailsPostDemand" show-overflow-tooltip />
      <el-table-column label="岗位发展路径" align="center" prop="rDetailsPostGrow" show-overflow-tooltip />
      <el-table-column label="企业文化" align="center" prop="rDetailsBusinessCulture" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['zua:details:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            v-hasPermi="['zua:details:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改details对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="就业名称" prop="rRecruitId" label-width="120px">
          <el-input v-model="form.rRecruitId" :readonly="true" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="详细名称" prop="rDetailsName" label-width="120px">
          <el-input v-model="form.rDetailsName" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="岗位简介" prop="rDetailsRemake" label-width="120px">
          <el-input v-model="form.rDetailsRemake" type="textarea" placeholder="请输入岗位简介" />
        </el-form-item>
        <el-form-item label="岗位" prop="rDetailsPost" label-width="120px">
          <el-input v-model="form.rDetailsPost" placeholder="请输入详细岗位" />
        </el-form-item>
        <el-form-item label="热招岗位" prop="rDetailsPostHeat" label-width="120px">
          <el-input v-model="form.rDetailsPostHeat" placeholder="请输入详细热招岗位" />
        </el-form-item>
        <el-form-item label="岗位要求" prop="rDetailsPostDemand" label-width="120px">
          <el-input v-model="form.rDetailsPostDemand" type="textarea" placeholder="请输入岗位要求" />
        </el-form-item>
        <el-form-item label="岗位发展路径" prop="rDetailsPostGrow" label-width="120px">
          <el-input v-model="form.rDetailsPostGrow" type="textarea" placeholder="请输入岗位发展路径" />
        </el-form-item>
        <el-form-item label="企业文化" prop="rDetailsBusinessCulture" label-width="120px">
          <el-input v-model="form.rDetailsBusinessCulture" type="textarea" placeholder="请输入企业文化" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="createButton" @click="submitForm">立即创建</el-button>
          <el-button @click="cancel">取 消</el-button>
        </el-form-item>
      </el-form></el-dialog>
  </div>
</template>

<script>
import { listDetails, getDetails, delDetails, addDetails, updateDetails, exportDetails } from '@/api/zua/details'
import { getRecruit } from '@/api/zua/recruit'
export default {
  name: 'Details',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedZuaRecruit: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // details表格数据
      detailsList: [],
      // ${subTable.functionName}表格数据
      zuaRecruitList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rRecruitId: null,
        rDetailsName: null,
        rDetailsRemake: null,
        rDetailsPost: null,
        rDetailsPostHeat: null,
        rDetailsPostDemand: null,
        rDetailsPostGrow: null,
        rDetailsBusinessCulture: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rRecruitId: [
          { required: true, message: '就业信息主表id不能为空', trigger: 'blur' }
        ]
      },
      // 接收传过来的对象
      recruit: {}
    }
  },
  async created() {
    this.recruit.recruitId = this.$route.params && this.$route.params.recruitId
    await this.getRecruits(this.recruit.recruitId)
    this.queryParams.rRecruitId = this.recruit.recruitId
    this.getList()
  },
  methods: {
    // 查询recruit的详细数据
    async getRecruits(id) {
      await getRecruit(id).then(res => {
        this.recruit = res.data
      })
    },
    /** 查询details列表 */
    async getList() {
      this.loading = true
      await listDetails(this.queryParams).then(response => {
        this.detailsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        rDetailsId: null,
        rRecruitId: null,
        rDetailsName: null,
        rDetailsRemake: null,
        rDetailsPost: null,
        rDetailsPostHeat: null,
        rDetailsPostDemand: null,
        rDetailsPostGrow: null,
        rDetailsBusinessCulture: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.zuaRecruitList = []
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.rDetailsId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.form.rRecruitId = this.recruit.recruitName
      this.open = true
      this.title = '添加详细信息'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const rDetailsId = row.rDetailsId || this.ids
      getDetails(rDetailsId).then(response => {
        this.form = response.data
        this.zuaRecruitList = response.data.zuaRecruitList
        this.form.rRecruitId = this.recruit.recruitName
        this.open = true
        this.title = '修改岗位详细信息'
      })
    },
    /** 提交按钮 */
    async submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
        //   debugger
          this.form.zuaRecruitList = this.zuaRecruitList
          this.form.rRecruitId = this.recruit.recruitId
          if (this.form.rDetailsId != null) {
            updateDetails(this.form).then(response => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addDetails(this.form).then(response => {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    //   this.form.rRecruitId = this.recruit.recruitName
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const rDetailsIds = row.rDetailsId || this.ids
      this.$confirm('是否确认删除details编号为"' + rDetailsIds + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delDetails(rDetailsIds)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      })
    },
    /** 单选框选中数据 */
    handleZuaRecruitSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.zuaRecruit.clearSelection()
        this.$refs.zuaRecruit.toggleRowSelection(selection.pop())
      } else {
        this.checkedZuaRecruit = selection
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有details数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return exportDetails(queryParams)
      }).then(response => {
        this.download(response.msg)
      })
    }
  }
}
</script>
<style scoped>
.createButton{
    margin-left: 180px;
    /* border: 1px solid red; */
}
</style>
